#pragma once
#include <iostream>
using namespace std;

void Char() {
	//字符
	//''表示单个字符
	//""表示字符串, 以结束符 '\0' 结尾
	char a = 'a';
	cout << "字符变量 a: " << a << endl;
	cout << "字符变量 a 的 ASCII 码: " << int(a) << endl;

	cout << "字符变量 a - 32: " << a - 32 << endl;
	cout << "字符变量 a - 32 的 ASCII 码: " << int(a) << endl;

	if (a + 32 == 'a')
		cout << "字符变量 a + 32 == 'a': " << a << endl;

	a = 'b';
	cout << "字符变量 a 赋值为 'b' : " << a << endl;
	char b = a - 'a' + 'A';
	cout << "字符变量(小写转为大写) a - 'a' + 'A': " << b << endl;
}

void CharArray() {
	//字符数组
	//aArr[5] 放入hello足够, 但是在输出时却不够, cout输出时是按照字符串进行输出, 字符串需要 '\0' 结尾
	char aArr[5] = { 'h', 'e', 'l', 'l', 'o' };
	cout << "字符数组aArr[5]: " << aArr << endl;
	cout << "迭代输出字符数组aArr[5]: ";
	for (char t : aArr) {
		cout << t << " ";
	}
	cout << endl;

	char aArr1[6] = { 'h', 'e', 'l', 'l', 'o', '\0' };
	cout << "字符数组aArr1[6]: " << aArr1 << endl;

	//'\0'表示字符串结束的位置
	char aArr2[6] = { 'h', 'e', 'l', '\0', 'l', 'o' };
	cout << "字符数组aArr1[6]: " << aArr2 << endl;

	//将字符串赋值给字符数组
	char aArr3[6] = "hello";	//注意双引号, 且大小要比字符串大 1, 用于存储 '\0'
	//aArr3 = "hello";	错误
	cout << "字符数组aArr3[6]: " << aArr3 << endl;

	cout << "输入aArr4[6]: " << endl;
	char aArr4[6];
	cin >> aArr4;
	cout << "字符数组aArr4[6]: " << aArr4 << endl;
}